package org.jeecg.modules.tt_question_collect.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.tt_question_collect.entity.TtQuestionCollect;
import org.jeecg.modules.tt_question_collect.entity.wtexport;
import org.jeecg.modules.tt_question_collect.mapper.WtexportMapper;
import org.jeecg.modules.tt_question_collect.service.IWtexportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.util.*;

/**
 * @Description: 出具方案表
 * @Author: jeecg-boot
 * @Date:   2021-03-09
 * @Version: V1.0
 */
@Service
public class WtexportServiceImpl extends ServiceImpl<WtexportMapper, wtexport> implements IWtexportService {
	@Autowired
	private WtexportMapper wtexportMapper;


	@Override
	//jira同步列表
	public Page<wtexport> getexportlist(Page<wtexport> pagelist, wtexport wtexport) {
		if ("1".equals(wtexport.getIsjira())) {
			wtexport.setBy1("已同步");
		} else if ("2".equals(wtexport.getIsjira())) {
			wtexport.setBy2("未同步");
		}

		if(wtexport.getTitlesummary()!=null){
		String str =	wtexport.getTitlesummary().replaceAll("\\*","");
			System.out.println(str);
			wtexport.setTitlesummary(str);
		}


			//问题导出列表
			return wtexportMapper.getwtexportlist(pagelist, wtexport);

	}

	@Override
	public Page<wtexport> getyxjpxlist(Page<wtexport> pagelist, wtexport wtexport) {
		return wtexportMapper.getyxjpxlist(pagelist, wtexport);
	}

	@Override
	public void updateyxjbj(String id, Integer highestbj) {
		wtexportMapper.updateyxjbj(id, highestbj);
	}

	//问题累计用时
	@Override
	public Page<TtQuestionCollect> queryljtime(Page<TtQuestionCollect> page, TtQuestionCollect ttQuestionCollect) throws ParseException {
		return wtexportMapper.queryljtime(page, ttQuestionCollect);

	}


	@Override
	public Integer querybmtjdata(String bmcode) {
		return wtexportMapper.querybmtjdata(bmcode);
	}

	//统计各部门问题相关柱状图数据
	@Override
	public List<Map<String, Object>> getbmcode() {
		List<Map<String, Object>> map = wtexportMapper.getbmcode();

		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> hashmap = new HashMap<>();
		Map<String, Object> hashmap2 = new HashMap<>();
		Map<String, Object> hashmap3 = new HashMap<>();
		Map<String, Object> hashmap4 = new HashMap<>();
		Map<String, Object> hashmap5 = new HashMap<>();
		hashmap.put("type", "提交问题数量");
		hashmap2.put("type", "未审核数量");
		hashmap3.put("type", "已审核数量");
		hashmap4.put("type", "方案完成数量");
		hashmap5.put("type", "研发完成数量");
		for (int i = 0; i < map.size(); i++) {

			//各个部门提交问题的数量
			Integer bmwttjnum = wtexportMapper.querybmtjdata(map.get(i).get("ORG_CODE").toString());
			hashmap.put(map.get(i).get("DEPART_NAME").toString(), bmwttjnum);

			//各个部门未审核数量
			Integer wshnum = wtexportMapper.querywshnumdata(map.get(i).get("ORG_CODE").toString());
			hashmap2.put(map.get(i).get("DEPART_NAME").toString(), wshnum);

			//各部门已审核数量
			Integer yshnum = wtexportMapper.queryyshnumdata(map.get(i).get("ORG_CODE").toString());
			hashmap3.put(map.get(i).get("DEPART_NAME").toString(), yshnum);

			//方案完成数量
			Integer fawcnum = wtexportMapper.queryfawcnumdata(map.get(i).get("ORG_CODE").toString());
			hashmap4.put(map.get(i).get("DEPART_NAME").toString(), fawcnum);

			//研发完成数量
			Integer yfwcnum = wtexportMapper.queryyfwcnumdata(map.get(i).get("ORG_CODE").toString());
			hashmap5.put(map.get(i).get("DEPART_NAME").toString(), yfwcnum);

		}
		//添数据
		list.add(hashmap);
		list.add(hashmap2);
		list.add(hashmap3);
		list.add(hashmap4);
		list.add(hashmap5);
		return list;
	}


	//统计各审批人待审批和已审批数据
	@Override
	public List<Map<String, Object>> getsprdata() {

		//获取审批角色的id
		String roleid = wtexportMapper.queryrolelist();
		List<Map<String, Object>> userlist = wtexportMapper.queryuserlist(roleid);

		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> hashmap = new HashMap<>();
		Map<String, Object> hashmap2 = new HashMap<>();

		hashmap.put("type", "已审核问题数量");
		hashmap2.put("type", "待审核问题数量");

		for (int i = 0; i < userlist.size(); i++) {
			//已审批
			Integer yspnum = wtexportMapper.getsprysp(userlist.get(i).get("ID").toString());
			hashmap.put(userlist.get(i).get("REALNAME").toString(), yspnum);
			//待审批
			Integer dspnum = wtexportMapper.getsprdsp(userlist.get(i).get("ID").toString());
			hashmap2.put(userlist.get(i).get("REALNAME").toString(), dspnum);

		}
		list.add(hashmap);
		list.add(hashmap2);

		return list;
	}

	@Override
	public String getsyckdspnum() {
		LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		return wtexportMapper.getsyckdspnum(user.getId());
	}



	@Override
	public List<Map<String, Object>> getfilelist(String ids) {
		List<Map<String, Object>> listmap = new ArrayList<>();

		Map<String, Object> wtmap = new HashMap<>();
		Map<String, Object> famap = new HashMap<>();

		//附件查看
		Map<String, Object> fileidtitlelist = wtexportMapper.getfilelist(ids);
		if (fileidtitlelist!=null){
			wtmap.put("title",fileidtitlelist.get("TITLESUMMARY"));

			System.out.println(fileidtitlelist.get("FILEGUID"));
			if (fileidtitlelist.get("FILEGUID")!=null){
				String[] wtidarr = fileidtitlelist.get("FILEGUID").toString().split(",");
				wtmap.put("wtfileguid",wtidarr);
			}

			listmap.add(wtmap);
		}


		String  faids = wtexportMapper.getfaidbyid(ids);
		if(faids!=null){
			String[] faidarr = faids.split(",");
			famap.put("fafileguid",faidarr);
			listmap.add(famap);

		}

		return listmap;
	}




}
